<?php
/**
 * @copyright  For copyright and license information, read the COPYING.txt file.
 * @link       /COPYING.txt
 * @license    Academic Free License (AFL 3.0)
 * @package     default_default
 */

/**
 * @see Mage_Adminhtml_Block_Catalog_Product_Created
 * @var Mage_Adminhtml_Block_Catalog_Product_Created $this
 */
?>
<script type="text/javascript">
var added = false;
function addProduct(closeAfter) {
    if(window.opener != null && !added) {
        if (window.opener.superProduct) {
            <?php if($this->isEdit()): ?>
            window.opener.superProduct.updateProduct(<?php echo $this->getProductId() ?>, <?php echo $this->getAttributesJson(); ?>);
            <?php else: ?>
            window.opener.superProduct.addNewProduct(<?php echo $this->getProductId() ?>, <?php echo $this->getAttributesJson(); ?>);
            window.opener.superProduct.showNoticeMessage();
            <?php endif ?>
            added = true;
        } else if (window.opener.catalog_category_productsJsObject) {
            window.opener.catalog_category_productsJsObject.reload(null);
        }
    }

    if(closeAfter)
    {
        closeWindow();
    }
}

function closeWindow()
{
    if (window.opener) {
        window.opener.focus();
    }
    window.close();
}

addProduct(false);
setTimeout(closeWindow, 3000);
</script>
<div class="a-center">
<?php echo $this->getCloseButtonHtml() ?>
</div>
